<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button>点赞(<span>4</span>)</button>
    <button>点赞(<span>3</span>)</button>
    <button>点赞(<span>2</span>)</button>
    <button>点赞(<span>1</span>)</button>

    <script>
        //获取按钮和数字元素
        var btns = document.querySelectorAll('button');
        var spans = document.querySelectorAll('span');
        //遍历按钮
        for (var i = 0; i < btns.length; i++) {
            btns[i].onclick = (function (index) {
                return function () {
                    console.log(index);
                    //单击一次相应按钮，该按钮数字增加
                    spans[index].innerHTML++;
                }
            })(i);
        }
    </script>
</body>

</html>